/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.sd.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.utils.excel.ExcelExport;
import com.jeesite.modules.sd.entity.DocDeliverRecord;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sd.entity.DocLog;
import com.jeesite.modules.sd.service.DocLogService;

import java.util.List;

/**
 * 涉密文件日志审计Controller
 * @author ysj
 * @version 2020-07-07
 */
@Controller
@RequestMapping(value = "${adminPath}/sd/docLog")
public class DocLogController extends BaseController {

	@Autowired
	private DocLogService docLogService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DocLog get(String id, boolean isNewRecord) {
		return docLogService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sd:docLog:view")
	@RequestMapping(value = {"list", ""})
	public String list(DocLog docLog, Model model) {
		model.addAttribute("docLog", docLog);
		return "modules/sd/docLogList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("sd:docLog:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DocLog> listData(DocLog docLog, HttpServletRequest request, HttpServletResponse response,String order) {
		docLog.setPage(new Page<>(request, response));
		//来文页面查看日志进行时间升序排序
		if(StringUtils.isNotEmpty(order)&&StringUtils.isEmpty(docLog.getOrderBy())){
			docLog.getSqlMap().getOrder().setOrderBy(order);
		}
		Page<DocLog> page = docLogService.findPage(docLog);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sd:docLog:view")
	@RequestMapping(value = "form")
	public String form(DocLog docLog, Model model) {
		model.addAttribute("docLog", docLog);
		return "modules/sd/docLogForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("sd:docLog:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DocLog docLog) {
		docLogService.save(docLog);
		return renderResult(Global.TRUE, text("保存涉密文件日志审计成功！"));
	}


	@PostMapping(value = "exportData")
	public void exportData( DocLog docLog, Boolean isAll, String ctrlPermi, HttpServletResponse response, HttpServletRequest request) {

		List<DocLog> list = this.docLogService.findList(docLog);
		String fileName = "日志记录" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
		ExcelExport ee = new ExcelExport("日志记录", DocLog.class);
		Throwable var8 = null;

		try {
			ee.setDataList(list).write(response, fileName);
		} catch (Throwable var17) {
			var8 = var17;
			throw var17;
		} finally {
			if (ee != null) {
				if (var8 != null) {
					try {
						ee.close();
					} catch (Throwable var16) {
						var8.addSuppressed(var16);
					}
				} else {
					ee.close();
				}
			}

		}

	}



}